// $Id$
// Interface of ExtendedCamera
//
// ml278
// Copyright (C) 2008 Bjørn Øivind Bjørnsen, Aleksander Gjermundsen, Knut Andre Tidemann, Thomas Hansen
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

#ifndef __EXTENDED_CAMERA_H
#define __EXTENDED_CAMERA_H

#include "Ogre.h"

#include <OgreOctreeCamera.h>

using namespace Ogre;

namespace ml278 
{
	/// movement directions
	enum MoveDirection{FORWARD, BACKWARD, STRAFE_LEFT, STRAFE_RIGHT};

	/**
	 * An extension of the OGRE Camera and the OctreeCamera classes.
	 * Provides possibilities to follow an object with syncronised yaw, pitch and roll in
	 * third person and first person perspectives.
	*/
	class ExtendedCamera : public OctreeCamera
	{
	private:
		SceneNode *mCameraNode;		/**< the camera is attached to this scenenode */
		SceneNode *mTargetNode;		/**< scenenode the camera is pointing at when not manually controlled */
		SceneNode *mFollowNode;		/**< scenenode following the target at a static distance */
		SceneManager *mSceneMgr;	/**< ogre scenemanager used */
		
		bool mManualControl;		/**< true if manual control is enabled, false if chasing a scenenode */
		bool mMovementDir[4];		/**< array of bools for each movement direction (for manual control), true if moving */
		float mMovementStep;		/**< factor controlling the movement speed of the manual camera */
		Vector3 mTargetUp;		/**< target scenenode UP-vector, recalculated on update */
		Vector3 mTargetDistance;	/**< distance to target scenenode */
	public:
		ExtendedCamera(String name, SceneManager *mgr);
		~ExtendedCamera();
		
		void setPosition(Vector3 pos);
		void setDistanceToTarget(Vector3 dist);
		
		void setTarget(SceneNode *target);
		const SceneNode *getTarget();
		
		void enableManualControl(bool);
		bool isManuallyControlled();
		bool manualYaw(Radian rad);
		bool manualPitch(Radian rad);
		bool manualRoll(Radian rad);
		bool move(ml278::MoveDirection dir, bool move);

		void update(Real elapsedTime);
	};
}
#endif

